package leetcode.weekly.week303;

//Solution2Test
public class Solution2 {

	public int equalPairs(int[][] grid) {
		int m = grid.length, n = grid[0].length;
		int ans = 0;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if (this.same(i, j, grid)) {
					ans++;
				}
			}
		}
		return ans;
	}

	private boolean same(int r, int c, int[][] grid) {
		int n = grid.length;
		for (int i = 0; i < n; i++) {
			if (grid[r][i] != grid[i][c]) {
				return false;
			}
		}
		return true;
	}

}
